import { getUserInfo } from "@/api/user";
import { TOKEN_NAME } from "@/config";
import { setStorage } from "@/utils/utils";
import { call, put } from "redux-saga/effects";

export function* login({ payload, callback }: any): Generator {
  const user: any = yield call(getUserInfo, payload);
  console.log("user", user);
  if (user?.data.token) {
    setStorage(TOKEN_NAME, user?.data?.token);
    window.location.replace("/");
    yield put({ type: "LOGIN", user: user.data });
    callback && callback();
  }
}
export function* setUserInfo({ payload }: any): Generator {
  yield put({ type: "SET_USER", user: payload });
}
